%sm_dewarp
t0=clock;
xs=0.324;
ys=0.309;
%im31
xpx=737;%pixels
ypx=672;
xL=240;
yL=195;
[dp_true1,dp_warp1,p_center1]=sm_getcalidata2('grid31ture.txt','grid31.txt',xs,ys);%,xpx,ypx,xL,yL);
[np,tmp]=size(dp_true1);
p_true1=dp_true1+repmat(p_center1,np,1);
p_warp1=dp_warp1+repmat(p_center1,np,1);
%im32
xpx=781;
ypx=629;
xL=255;
yL=180;
[dp_true2,dp_warp2,p_center2]=sm_getcalidata2('grid31ture.txt','grid32.txt',xs,ys);%,xpx,ypx,xL,yL);
[np,tmp]=size(dp_true2);
p_true2=dp_true2+repmat(p_center2,np,1);
p_warp2=dp_warp2+repmat(p_center2,np,1);
%im33
xpx=784;
ypx=626;
xL=255;
yL=180;
[dp_true3,dp_warp3,p_center3]=sm_getcalidata2('grid33ture.txt','grid33.txt',xs,ys);%xpx,ypx,xL,yL);
[np,tmp]=size(dp_true3);
p_true3=dp_true3+repmat(p_center3,np,1);
p_warp3=dp_warp3+repmat(p_center3,np,1);
%im34
xpx=784;
ypx=625;
xL=255;
yL=180;
[dp_true4,dp_warp4,p_center4]=sm_getcalidata2('grid34ture.txt','grid34.txt',xs,ys);%xpx,ypx,xL,yL);
[np,tmp]=size(dp_true4);
p_true4=dp_true4+repmat(p_center4,np,1);
p_warp4=dp_warp4+repmat(p_center4,np,1);
%im35
xpx=781;
ypx=629;
xL=255;
yL=180;
[dp_true5,dp_warp5,p_center5]=sm_getcalidata2('grid35ture.txt','grid35.txt',xs,ys);%xpx,ypx,xL,yL);
[np,tmp]=size(dp_true5);
p_true5=dp_true5+repmat(p_center5,np,1);
p_warp5=dp_warp5+repmat(p_center5,np,1);
%im36
xpx=781;
ypx=630;
xL=255;
yL=180;
[dp_true6,dp_warp6,p_center6]=sm_getcalidata2('grid31ture.txt','grid36.txt',xs,ys);%xpx,ypx,xL,yL);
[np,tmp]=size(dp_true6);
p_true6=dp_true6+repmat(p_center6,np,1);
p_warp6=dp_warp6+repmat(p_center6,np,1);

dp_true=[dp_true1;dp_true2;dp_true3;dp_true4;dp_true5;dp_true6];%[p_true1;p_true2]-repmat(p_center1,2*np,1);
dp_warp=[dp_warp1;dp_warp2;dp_warp3;dp_warp4;dp_warp5;dp_warp6];%[p_warp1;p_warp2]-repmat(p_center1,2*np,1);
p_warp=[p_warp1;p_warp2;p_warp3;p_warp4;p_warp5;p_warp6];
p_true=[p_true1;p_true2;p_true3;p_true4;p_true5;p_true6];
n_equ=5;
x_max=960;
y_max=1280;
A1=sm_bernstein2d3(dp_true,dp_warp,p_warp,x_max,y_max,n_equ);
A2=sm_bernstein2d3(dp_warp,dp_true,p_true,x_max,y_max,n_equ);

[I_new1,ee1]=sm_imdewarp('dataset_grid\im_00031.jpeg',A1,A2,dp_true1,dp_warp1,p_center1,n_equ);
[I_new2,ee2]=sm_imdewarp('dataset_grid\im_00032.jpeg',A1,A2,dp_true2,dp_warp2,p_center2,n_equ);
[I_new3,ee3]=sm_imdewarp('dataset_grid\im_00033.jpeg',A1,A2,dp_true3,dp_warp3,p_center3,n_equ);
[I_new4,ee4]=sm_imdewarp('dataset_grid\im_00034.jpeg',A1,A2,dp_true4,dp_warp4,p_center4,n_equ);
[I_new5,ee5]=sm_imdewarp('dataset_grid\im_00035.jpeg',A1,A2,dp_true5,dp_warp5,p_center5,n_equ);
[I_new6,ee6]=sm_imdewarp('dataset_grid\im_00036.jpeg',A1,A2,dp_true6,dp_warp6,p_center6,n_equ);
ee=[ee1;ee2;ee3;ee4;ee5;ee6];

etime(clock,t0)